package com.mlz.mlzmall.ui.utils.vali;

import android.content.Context;
import android.content.SharedPreferences;

/**
 * @description 工具类
 * @vresion 1.0
 * Created by 安帅 on 2015/10/13 18:38.
 */
public class Tools {
    private static SharedPreferences mSp;
    public static final String SP_NAME = "exiu_sp";//以sp存储的xml文件名
    public static final String IS_FIRST_USE = "is_first_use";//以sp存储的xml文件名

    public static SharedPreferences getSharedPreferences(Context context) {
        if (mSp == null) {
            mSp = context.getSharedPreferences(SP_NAME, Context.MODE_PRIVATE);
        }
        return mSp;
    }

    //取布尔值
    public static boolean getBoolean(Context context, String key, boolean delvalue) {
        SharedPreferences sp = getSharedPreferences(context);

        return sp.getBoolean(key, delvalue);
    }

    public static boolean getBoolean(Context context, String key) {
        SharedPreferences sp = getSharedPreferences(context);

        return sp.getBoolean(key, false);
    }

    //设置布尔值
    public static void setBoolean(Context context, String key, boolean value) {
        SharedPreferences sp = getSharedPreferences(context);
        sp.edit().putBoolean(key, value).commit();//提交

    }

    //获取字符串数据
    public static String getString(Context context, String key,
                                   String defvalue) {
        SharedPreferences sp = getSharedPreferences(context);

        return sp.getString(key, defvalue);
    }

    //设置字符串数据
    public static void setString(Context context, String key, String value) {
        SharedPreferences sp = getSharedPreferences(context);
        sp.edit().putString(key, value).commit();//提交

    }


    //获取long数据
    public static long getLong(Context context, String key,
                               long defvalue) {
        SharedPreferences sp = getSharedPreferences(context);

        return sp.getLong(key, defvalue);
    }

    //设置字符串数据
    public static void setLong(Context context, String key, long value) {
        SharedPreferences sp = getSharedPreferences(context);
        sp.edit().putLong(key, value).commit();//提交

    }

}
